FROM cys/ubuntu-ssh-jdk8

# 省事, 在dockerfile指定下载
RUN wget https://mirrors.bfsu.edu.cn/apache/hadoop/common/hadoop-3.3.1/hadoop-3.3.1.tar.gz
RUN tar xvf hadoop-3.3.1.tar.gz
RUN mv hadoop-3.3.1 /usr/local/hadoop

# 为了加快速度, 也可以先下载好 hadoop, 然后再加进来
# RUN ADD hadoop-3.3.1.tar.gz /usr/local
# RUN mv /usr/local/hadoop-3.3.1 /usr/local/hadoop

ENV HADOOP_HOME /usr/local/hadoop
ENV PATH $HADOOP_HOME/bin:$PATH

# 覆盖配置文件
ADD hadoop_config/* /usr/local/hadoop/etc/hadoop/

# 增加环境变量
RUN echo 'export JAVA_HOME=/usr/local/jdk8' >> /usr/local/hadoop/etc/hadoop/hadoop-env.sh

# 配置 hosts
RUN echo '172.20.0.2 hadoop1' >> /etc/hosts
RUN echo '172.20.0.3 hadoop2' >> /etc/hosts
RUN echo '172.20.0.4 hadoop3' >> /etc/hosts

# 修改 start-dfs , 增加启动用户
RUN sed -i '/#!\/usr\/bin\/env bash/a\
				HDFS_DATANODE_USER=root\
				HDFS_DATANODE_SECURE_USER=hdfs\
				HDFS_NAMENODE_USER=root\
				HDFS_SECONDARYNAMENODE_USER=root\n' /usr/local/hadoop/sbin/start-dfs.sh

# 修改 stop-dfs , 增加启动用户
RUN sed -i '/#!\/usr\/bin\/env bash/a\
				HDFS_DATANODE_USER=root\
				HDFS_DATANODE_SECURE_USER=hdfs\
				HDFS_NAMENODE_USER=root\
				HDFS_SECONDARYNAMENODE_USER=root\n' /usr/local/hadoop/sbin/stop-dfs.sh
				
# 修改 start-yarn.sh
RUN sed -i '/#!\/usr\/bin\/env bash/a\
				YARN_RESOURCEMANAGER_USER=root\
				HADOOP_SECURE_DN_USER=yarn\
				YARN_NODEMANAGER_USER=root\n' /usr/local/hadoop/sbin/start-yarn.sh
				
# 修改 stop-yarn.sh
RUN sed -i '/#!\/usr\/bin\/env bash/a\
				YARN_RESOURCEMANAGER_USER=root\
				HADOOP_SECURE_DN_USER=yarn\
				YARN_NODEMANAGER_USER=root\n' /usr/local/hadoop/sbin/stop-yarn.sh
				
# 修改 workers 文件
# 将localhost替换掉
RUN echo 'hadoop2' > /usr/local/hadoop/etc/hadoop/workers 
RUN echo 'hadoop3' >> /usr/local/hadoop/etc/hadoop/workers 


